<template>
  <div>
    <el-table
      :data="userlist"
      :tree-props="{ children: 'children' }"
      row-key="id"
      default-expand-all
      border
      style="width: 100%"
    >
      <el-table-column prop="id" label="分类编号" width="180"> </el-table-column>
      <el-table-column prop="catename" label="分类名称" width="180"> </el-table-column>
      <el-table-column prop="img" label="图片" width="180">
        <template slot-scope="item">
          <img v-if="item.row.img" class="imgUrl" :src="item.row.img" alt="" />
        </template>
      </el-table-column>
      <el-table-column label="状态" width="180">
        <template slot-scope="item">
          <div>{{ item.row.status == 1 ? "启用" : "禁用" }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="item">
          <div>
            <el-button type="primary" size="mini" plain @click="edit(item.row.id)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              plain
              circle
              icon="el-icon-delete"
              @click="del(item.row.id)"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { cateDelete } from "../../request/api.js";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      getCate: "cate/getCateListActions",
    }),
    edit(id) {
      this.$emit("edit", id);
    },
    // 删除事件
    del(id) {
      this.$confirm("你确定要删除？？？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          cateDelete({ id }).then((res) => {
            // console.log(res);
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.getCate();
              // this.$store.dispatch("user/getUserListAction");
              // this.$store.dispatch('user/getUserCount')
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  mounted() {
    this.$store.dispatch("cate/getCateListActions");
  },
  watch: {},
  computed: {
    ...mapGetters({
      userlist: "cate/getCate",
    }),
  },
  filters: {},
  components: {},
};
</script>
<style scoped>
.imgUrl {
  width: 60px;
  height: 60px;
}
</style>
